﻿using System;
namespace Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="MokaRequest", Namespace="http://producers.liiklusregister.xtee.riik.ee/producer/liiklusregister", Target=typeof(MokaRequest))]
    public class MokaRequestSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IMokaRequest clazz;
        
        public MokaRequestSerializer(IMokaRequest clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("Moka");
            if (clazz.Moka!=null) {
                global::Xtee.Core.SerializationMetadata metaMoka = this.GetMetaData(clazz.Moka);
                Writer.WriteTypeAttribute(metaMoka.TypeQualifiedName.Namespace, metaMoka.TypeQualifiedName.Name);
                metaMoka.NewSerializer(clazz.Moka).WriteXml(Writer);
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Moka");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="Moka") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>MokaRequest>Moka");
                }
                global::Xtee.Core.SerializationMetadata metaMoka = this.GetMetaData<global::Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister.IMokaType>(Reader, "MokaType", "http://producers.liiklusregister.xtee.riik.ee/producer/liiklusregister");
                clazz.Moka = metaMoka.NewEntity<global::Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister.IMokaType>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("Moka");
                    metaMoka.NewSerializer(clazz.Moka).ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>MokaRequest>Moka", Reader.LocalName);
            }
        }
    }
}
